#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int longestOnes(vector<int>& nums, int k)
    {
        int left = 0, right = 0, n = nums.size(), len = 0;
        int zero = 0;
        while (right < n)
        {
            if (nums[right] == 0)
            {
                zero++;
            }
            while (zero > k)
            {
                if (nums[left++] == 0)
                {
                    zero--;
                }
            }
            len = max(len, right - left + 1);
            right++;
        }
        return len;
    }
};

void test()
{
    vector<int> nums = { 1,1,1,0,0,0,1,1,1,1,0 };
    Solution t;
    cout << t.longestOnes(nums, 2) << endl;

    //int n = 0;
    //if (n++ > 0)
    //{
    //    cout << "n > 0" << endl;
    //}
    //else
    //{
    //    cout << "n <= 0" << endl;
    //}
}

int main()
{
    test();
    return 0;
}